<template>
  <div class="login_body">
    <particles id="tsparticles" :options="particles_login"> </particles>
    <div class="login_form">
      <h1 class="login_form_title">Vue3-Admin-Element-Template</h1>

      <el-form
        ref="formRef"
        :model="ruleForm"
        :rules="rules"
        label-width="auto"
        label-position="top"
        status-icon
        size="large"
      >
        <div class="login_form_item">
          <el-form-item label="用户名:" prop="name">
            <el-input v-model="ruleForm.name" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item label="密码:" prop="password">
            <el-input
              v-model="ruleForm.password"
              type="password"
              placeholder="请输入密码"
            />
          </el-form-item>

          <div class="login_form_button">
            <el-button type="primary" @click="handleLogin">登录</el-button>
          </div>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import router from "@/router";
import { ref } from "vue";
import { setCookies } from "@/utils/cookie.js";
import { particles_login } from "@/utils/particles-config.js";
export default {
  setup() {
    const formRef = ref();
    const ruleForm = ref({
      name: "admin",
      password: "password",
    });
    const rules = ref({
      name: { required: true, message: "请输入用户名", trigger: "change" },
      password: { required: true, message: "请输入密码", trigger: "change" },
    });

    const handleLogin = () => {
      formRef.value.validate(async (valid) => {
        if (valid) {
          setCookies("token", "TOKADADA12313");
          router.push("/Home");
        }
      });
    };
    return {
      ruleForm,
      rules,
      formRef,
      particles_login,
      handleLogin,
    };
  },
};
</script>
<style lang="less" scoped>
.login_body {
  height: 100vh;
  width: 100vw;
  background-size: cover;
  background-repeat: no-repeat;
  background-image: url("@/styles/img/login_background.png");
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  .login_form {
    z-index: 2;
    position: absolute;
    width: 35vw;
    padding: 30px 15px;
    background: #fff;
    border-radius: 5px;
    box-shadow: 0 2px 12px 0 black;
    .login_form_title {
      margin-bottom: 13px;
      text-align: center;
    }
    .login_form_item {
      margin: 0 16px;
    }
    .login_form_button {
      width: 100%;
      .el-button {
        width: 100%;
      }
    }
  }
}
</style>
